// 分析所有.detail.txt文件内容，获得高频关键词
// Top20、30、40分别存入响应的top.json文件中

const { resolve } = require('path');
const env = require(resolve('./config.js'));
const fs = require('fs');
const { load, extract, cut } = require('@node-rs/jieba');
const dp = env[env.mode];
let str = '';
let url = resolve('./out/front end/front end_');
console.log('开始处理数据');
for (let item of dp) {
    let path = url + `${item.code}.detail.txt`;
    str += fs.readFileSync(path, 'utf8').replace(/[\d\s。、，；：;:\.•\s/()（）]/gs, '').toString();
}
load();
fs.writeFileSync(url + 'cutAll.txt', cut(str).join(' '));
console.log('数据清洗成功，成功写入cutAll.txt');
fs.writeFileSync(url + 'Top20.json', JSON.stringify(extract(str, 20)));
console.log('Top20已写入JSON文件');
fs.writeFileSync(url + 'Top30.json', JSON.stringify(extract(str, 30)));
console.log('Top30已写入JSON文件');
fs.writeFileSync(url + 'Top40.json', JSON.stringify(extract(str, 40)));
console.log('Top40已写入JSON文件');

